var tableIns;//表格实例
layui.config({
	base: '../../../eui/plugins/layui-extend/' //这是你存放拓展模块的根目录
});
layui.use(function() {
	var treeTable = layui.treeTable;
	var form = layui.form;
	// 渲染
	tableIns = treeTable.render({
		elem: '#lTable',
		url: appendCtx('/strategy/strategies'), // 此处为静态模拟数据，实际使用时需换成真实接口
		tree: {
			customName: {
				name: "strategyName",
			},
			view:{
				expandAllDefault: true
			}
		},
		maxHeight: '500px',
		cols: [[
			{ field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left' },
			{ field: 'strategyName', title: '节点名称', width: 300, fixed: 'left' },
			{
				field: 'type', title: '节点类型', width: 180, fixed: 'center', templet:
					function(d) {
						return translate("strategyNodeType", d.type);
					}
			},
			{ field: 'remark', title: '备注', width: 260, fixed: 'left' },
			{ field: 'createUserName', title: '创建人员', width: 120, fixed: 'left' },
			{ field: 'createTime', title: '创建时间', width: 180, fixed: 'left' },
			{ fixed: "right", title: "操作", width: 300, align: "left", toolbar: "#operateTp" }
		]]
		, page: {
			limit: 10,
			limits: [10, 30, 50, 100]
		}
		, request: {
			pageName: 'pageNo' //页码的参数名称，默认：page
			, limitName: 'pageSize' //每页数据量的参数名，默认：limit
		}
		, parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.msg, //解析提示文本
				"count": res.data.total, //解析数据长度
				"data": res.data.list //解析数据列表
				, "attr": res.attr
			};
		},
	});
	
	form.on('submit(add)', function(){
    	layer.open({
            type: 2,
            title: '新增节点',
            area: ['650px', '450px'],
            content: 'edit.html',
        });
        return false;
    });
});

function refreshTableData(){
    tableIns.reload({});
}

function strategy(id,strategyName) {
	addMenuTab(appendCtx('/pages/strategy/strategy/strategy.html?id='+id),"策略开发-"+strategyName,"fa fa-heartbeat");
}

function edit(id) {
	layer.open({
		type: 2,
		title: typeof (id) != "undefined" ? '修改节点' : '新增节点',
		shadeClose: true,
		area: ['650px', '450px'],
		content: 'edit.html?id=' + id,
	});
}

function del(id) {
	io.delete("/strategy/strategies/" + id, function(res) {
		refreshTableData();
	});
}